$(document).ready(function () {
    toastr.options = {
        "closeButton": true,
        "debug": false,
        "progressBar": true,
        "positionClass": "toast-top-right",
        "onclick": null,
        "showDuration": "400",
        "hideDuration": "1000",
        "timeOut": "7000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    }
    let flag = true;
    $("#inlineCheckbox2").on('click', function () {
        if (flag) {
            $("input[name='inp-check-box']").prop("checked", true);
            flag = false;
        } else {
            $("input[name='inp-check-box']").prop("checked", false);
            flag = true;
        }
    });

});

function uploadTemplateExcel(){
    console.log("111");
    let formData=new FormData();
    formData.append("file",$(".file")[0].files[0]);
    //formData.append("file",$(obj).parents('tr').find('td').eq(7).find('#file')[0].files[0]);
    console.log(formData);
    $.ajax({
        type:"POST",
        url:"/admin/file/bproduct/upload",
        data:formData,
        cache:false,
        contentType:false,
        processData:false,
        dataType:"json",
        success:function (response) {
            console.log(response);
            if(response !== 0){
                toastr.success("上传成功","提示：");
                setTimeout(function () {
                    window.location.reload();
                },2000)
            }else{
                toastr.error("上传失败,请重试","提示：");
            }
        }
    })
}

function downloadTemplate(){
    location.href='/admin/file/bproduct/download'
}

function uploadExcel2Db(){
    let formData=new FormData();
    formData.append("file",$("#excel")[0].files[0]);
    //formData.append("file",$(obj).parents('tr').find('td').eq(7).find('#file')[0].files[0]);
    console.log(formData);
    $.ajax({
        type:"POST",
        url:"/admin/file/bproduct/uploadCvs",
        data:formData,
        cache:false,
        contentType:false,
        processData:false,
        dataType:"json",
        success:function (response) {
            console.log(response);
            if(response !== 0){
                toastr.success("上传成功","提示：");
                setTimeout(function () {
                    window.location.reload();
                },2000)
            }else{
                toastr.error("上传失败,请重试","提示：");
            }
        }
    })
}

function updateBproduct(id){
    location.href='/admin/info/product/getOneBproduct/'+id
}

/**
 * 删除一个商品
 * @param id id
 */
function deleteBproduct(id){
    swal({
        title:"是否删除?",
        text:"请谨慎操作！",
        type:"warning",
        //是否显示取消按钮
        showCancelButton:true,
        //按钮内容
        cancelButtonText:'取 消',
        cancelButtonColor:'#b9b9b9',
        showConfirmButton:true,
        confirmButtonText:'确 认',
        confirmButtonColor:"#dd6b55",
        //点击返回上一步操作
        closeOnConfirm:false,
        closeOnCancel:true
    },function(){
        //正确按钮进行的操作点
        $.ajax({
            url:'/admin/info/product/delete/'+id,
            type:'DELETE',
            success:function (resp){
                if (resp.data){
                    toastr.success(resp.message,'提示')
                    setTimeout(function () {
                        window.location.reload()
                    },2000)
                }else{
                    toastr.error(resp.message,'提示')
                }
            }
        })
    });
}